package Conexao;

import java.net.InetAddress;
import java.net.SocketException;
import java.util.HashMap;

import Protocolo.MiniTCP;

public class ServerListener implements Runnable {

	private MiniTCP socketListener;
	HashMap<InetAddress, MiniTCP> hash;
	
	public ServerListener(HashMap<InetAddress, MiniTCP> hash) {
		try {
			this.socketListener = new MiniTCP(3333);
			this.hash = hash;
		} catch (SocketException e) {
			e.printStackTrace();
		}
	}
	
	public void run() {
		while (true) {
			try {
				MiniTCP socket = socketListener.acceptConnection();
				socket.start();
				hash.put(socket.getAddress(), socket);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
